<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
    <el-form
      ref="queryForm"
      class="query-more-form"
      size="mini"
      label-width="100px"
      :model="query"
    >
      <el-row :gutter="21">
        <el-col :span="5">
          <el-form-item label="任务名称">
            <el-input
              v-model="query.name"
              class="search-ipt"
              placeholder="请输入任务名称"
              maxlength="255"
            />
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="时间区间">
            <el-date-picker
              v-model="query.startTime"
              type="datetimerange"
              size="mini"
              range-separator="-"
              start-placeholder="开始"
              end-placeholder="结束"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="任务部门">
            <el-select
              class="w-100"
              v-model="query.deptName"
              placeholder="请选择任务部门"
              clearable
            >
              <el-option
                v-for="item in department"
                :key="item.code"
                :value="item.sysDeptVo.deptName"
                :label="item.sysDeptVo.deptName"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4" class="btn-col">
          <el-button size="mini" class="search-btn" @click="select"
            >查询</el-button
          >
        </el-col>
      </el-row>
    </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <el-button class="flush-btn" size="mini" icon="el-icon-refresh"
          >刷新</el-button
        >
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-set-up"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData"
          :height="isShow ? 'calc(100vh - 410px)' : 'calc(100vh - 335px)'"
          style="width: 100%"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column prop="name" label="任务名称" show-overflow-tooltip />
          <el-table-column
            prop="randomCount"
            label="双随机巡检要求次数"
            show-overflow-tooltip
          />
          <el-table-column
            prop="randomActualCount"
            label="双随机巡检完成次数"
            show-overflow-tooltip
          />
          <el-table-column
            prop="itemCount"
            label="专项巡检要求次数"
            show-overflow-tooltip
          />
          <el-table-column
            prop="itemActualCount"
            label="专项巡检完成次数"
            show-overflow-tooltip
          />
          <el-table-column
            prop="dailyCount"
            label="日常巡检要求次数"
            show-overflow-tooltip
          />
          <el-table-column
            prop="dailyActualCount"
            label="日常巡检完成次数"
            show-overflow-tooltip
          />
          <el-table-column
            prop="randomRate"
            label="双随机巡检完成率"
            show-overflow-tooltip
          />
          <el-table-column
            prop="itemRate"
            label="专项巡检完成率"
            show-overflow-tooltip
          />
          <el-table-column
            prop="dailyRate"
            label="日常巡检完成率"
            show-overflow-tooltip
          />
        </el-table>
      </div>
      <div class="pagination-panel">
        <Pagination
          :total="query.total"
          :page.sync="query.pageNum"
          :limit.sync="query.pageSize"
          @pagination="select"
        />
      </div>
    </div>
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { getItemStatistics } from "@/api/system/doubleRandomMatters";

export default {
  name: "CaseDealDispatch",
  components: {
    SearchPanel,
    Pagination,
  },
  data() {
    return {
      query: {
        total: 1,
        pageNum: 1,
        pageSize: 10,
      },
      tableLoading: false,
      tableData: [],
      department: [],
      isShow: true,
    };
  },
  created() {
    this.initData()
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      this.select();
    },
    select() {
      this.tableLoading = true
      const query = JSON.parse(JSON.stringify(this.query))
      getItemStatistics(this.query)
        .then((result) => {
          console.log(result);
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
